#ifndef STORE_H_
#define STORE_H_
#include "n32wb03x.h"
#include "Typedefine.h"


#define LED_NUM   114



#define INIT_TAG 0x01
#define INIT_EVT 0x81


#define PICS_TAG 0x02
#define PICS_EVT 0x82

#define END_TAG 0x03
#define END_EVT 0x83

#define DEL_TAG 0x04
#define DEL_EVT 0x84

#define INFO_TAG 0x05
#define INFO_EVT 0x85

#define TEST_MODE 0x06
#define NO_ERROR  0x00



#define VOIDF_VOD   0x1122
#define VOIDF_IND   0xFFFF
#define USEDF_USD   0x2233
#define USEDF_FRE   0xFFFF


#define VOIDF_OFS   0
#define USEDF_OFS   2
#define INDEX_OFS   4
#define PCSCN_OFS   6
#define PIC_0_OFS   8

#define  START_AREA     0x01010000
#define  END_AREA       0x0103C000
#define  SECTION_NUM_AREA    ((END_AREA - START_AREA)/0x1000)

#define SECTOR_VOIDDF(i)       (START_AREA + i*0x1000 + VOIDF_OFS)
#define SECTOR_VOIDF(i)        REG16(START_AREA + i*0x1000 + VOIDF_OFS)
#define SECTOR_USEDF(i)        REG16(START_AREA + i*0x1000 + USEDF_OFS)
#define SECTOR_INDEX(i)        REG16(START_AREA + i*0x1000 + INDEX_OFS)
#define SECTOR_PCS_N(i)        REG16(START_AREA + i*0x1000 + PCSCN_OFS)

#define PIC_N_OFS               0
#define PIC_KT_OFS              2
#define PIC_DA_OFS              4
#define SECTOR_PIC_NA(i, j)          (START_AREA + i*0x1000 + PIC_0_OFS + j*STORE_PIC_SIZE + PIC_N_OFS)
#define SECTOR_PIC_ND(i, j)     REG16(START_AREA + i*0x1000 + PIC_0_OFS + j*STORE_PIC_SIZE + PIC_N_OFS)
#define SECTOR_PIC_TA(i, j)          (START_AREA + i*0x1000 + PIC_0_OFS + j*STORE_PIC_SIZE + PIC_KT_OFS)
#define SECTOR_PIC_TD(i, j)     REG16(START_AREA + i*0x1000 + PIC_0_OFS + j*STORE_PIC_SIZE + PIC_KT_OFS)
#define SECTOR_PIC_DA(i, j)     (void *)(START_AREA + i*0x1000 + PIC_0_OFS + j*STORE_PIC_SIZE + PIC_DA_OFS) 

struct movs_ctrl_t{
    uint16_t mov_index[0x10];
    uint16_t free_pics;
    uint16_t cur_index;
    
};

struct store_pic_t
{
    uint16_t picn;
    uint16_t time;
    uint8_t  data[LED_NUM*3];
};  
#define STORE_PIC_SIZE  (LED_NUM*3+4)



void clear_void_sector(void);

#define CONST_MAX 10
#define USER_MAX  10

extern uint8_t strat_store_process;
extern uint8_t user_display_flag;
extern uint8_t user_display_num;
extern void (*const_dislay_array[USER_MAX])(void);
extern struct movs_ctrl_t movs;

void update_movs_index(void);
void ble_store_cb(uint8_t * data, uint16_t length);
void store_init(void);

#endif ///STORE_H_
